package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;
import com.example.utils.SortedListOf;

import org.testng.annotations.Test;

public class GroupModificationTests extends TestBase {

  @Test(dataProvider = "randomValidGroupGenerator")
  public void testGroupModification(GroupData group) throws Exception {
   
    // save old state
	SortedListOf<GroupData> oldlist = app.getGroupHelper().getGroups();
    
    Random rnd = new Random();
    int index = rnd.nextInt(oldlist.size()-1);
    
    //actions
    app.getGroupHelper().modifyGroup(index, group);
    
    //save new state
    SortedListOf<GroupData> newlist = app.getGroupHelper().getGroups();
 	 
 	 //compare states
  	 assertThat(newlist, equalTo(oldlist.without(index).withAdded(group)));  
  }

}
